import { getAreaObj } from '@/utils/util'
import { configToSearch, toSearchHandle } from '@/views/datacenter/business/utils/index'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '评定对象', prop: 'organizationName' },
		{ label: '所属地区', prop: 'tableAreaName', width: 220 },
		{ label: '评定人员', prop: 'evaluateStaff' },
		{ label: '评定单位', prop: 'evaluateUnit' },
		{
			label: '评定时间',
			prop: 'evaluateDate',
		},
		{
			label: '评定结果',
			prop: 'ultimatelyLevel',
			propName: 'ultimatelyLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
		},
		{
			label: '数据来源',
			prop: 'dateSource',
		},
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0, type: 'danger' },
				{ label: '是', value: 1, type: 'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}
export const formConfig = {
	label: '基础信息',
	prop: 'dp_service_object',
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	column: [
		// 等级评定机构基础档案
		{
			type: 'DividerHtml',
			custome: 'divider',
			position: 'center',
			modelValue: '等级评定机构基础档案',
			span: 24,
		},
		{
			type: 'DividerHtml',
			modelValue: '等级评定机构基础档案',
			span: 24,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构名称' }],
		},
		{
			label: '机构所属区域',
			prop: 'areas',
			propName: 'araes_name',
			type: 'AplidAreaSelect',
			span: 8,
			rules: [{ required: true, message: '请输入机构所属区域' }],
		},
		{
			label: '机构地址',
			prop: 'organizationAddress',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构地址' }],
		},
		{
			label: '机构类别',
			prop: 'organizationType',
			propName: 'organizationTypeLabel',
			type: 'remoteSelect',
			code: 'ORG_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择机构类别' }],
		},
		{
			label: '法定代表人姓名',
			prop: 'deputyUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入法定代表人姓名' }],
		},
		{
			label: '法定代表人联系电话',
			prop: 'deputyUserPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入法定代表人联系电话' }],
		},
		{
			label: '机构负责人姓名',
			prop: 'orgLeaderName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构负责人姓名' }],
		},
		{
			label: '机构负责人联系方式',
			prop: 'orgLeaderPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构负责人联系方式' }],
		},
		{
			label: '项目负责人姓名',
			prop: 'projectLeaderName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入项目负责人姓名' }],
		},
		{
			label: '项目负责人联系方式',
			prop: 'projectLeaderPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入项目负责人联系方式' }],
		},
		{
			label: '核定床位数',
			prop: 'realBedNum',
			type: 'text',
			append: '张',
			span: 8,
			rules: [{ required: true, message: '请输入核定床位数' }],
		},
		{
			label: '机构统一社会信用代码',
			prop: 'creditCode',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构统一社会信用代码' }],
		},
		{
			label: '营业执照(民非)证号',
			prop: 'organizationLicenseImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: false,
			span: 12,
		},
		{
			label: '机构设置证号(备案)',
			prop: 'organizationFilingImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: false,
			span: 12,
		},
		{
			label: '建筑工程消防验收合格意见书',
			prop: 'passAdviceImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: true,
			limit: 9,
			multiple: false,
			span: 12,
		},
		{
			label: '食品经营许可证',
			prop: 'foodPermitImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: false,
			span: 12,
		},

		// 评估档案
		{
			type: 'DividerHtml',
			custome: 'divider',
			position: 'center',
			modelValue: '评估档案',
			span: 24,
		},
		{
			type: 'DividerHtml',
			modelValue: '评估档案',
			span: 24,
		},
		{
			label: '申报日期',
			prop: 'declareDate',
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请选择申报日期' }],
		},
		{
			label: '申报星级等级',
			prop: 'declareLevel',
			propName: 'declareLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择申报星级等级' }],
		},
		{
			label: '专业支撑',
			prop: 'professionalSupport',
			propName: 'professionalSupportLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: false,
			span: 8,
			rules: [{ required: true, message: '请选择专业支撑' }],
		},
		{
			label: '养老志愿服务',
			prop: 'volunteerService',
			propName: 'volunteerServiceLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: false,
			span: 8,
			rules: [{ required: true, message: '请选择养老志愿服务' }],
		},
		{
			label: '医养结合',
			prop: 'medicalCare',
			propName: 'medicalCareLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: false,
			span: 8,
			rules: [{ required: true, message: '请选择医养结合' }],
		},

		{
			label: '评定日期',
			prop: 'evaluateDate',
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请选择申报日期' }],
		},
		{
			label: '关键项星级',
			prop: 'criticalLevel',
			propName: 'criticalLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择申报星级等级' }],
		},
		{
			label: '环境评分',
			prop: 'environment',
			type: 'text',
			append: '分',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '设施设备评分',
			prop: 'facilityEquipment',
			type: 'text',
			append: '分',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '运营设备评分',
			prop: 'operateEquipment',
			type: 'text',
			append: '分',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '服务评分',
			prop: 'service',
			type: 'text',
			append: '分',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '现场评定星级',
			prop: 'evaluateLevel',
			propName: 'evaluateLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择现场评定星级' }],
		},
		{
			label: '最终星级',
			prop: 'ultimatelyLevel',
			propName: 'ultimatelyLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择最终星级' }],
		},
		{
			label: '评定人员',
			prop: 'evaluateStaff',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '评定单位',
			prop: 'evaluateUnit',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '数据来源',
			prop: 'dateSource',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
	],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(formConfig.column)],
}
export const detailConfig = {
	label: '查看档案',
	prop: 'dp_service_object',
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	column: [
		// 等级评定机构基础档案
		{
			type: 'DividerHtml',
			modelValue: '等级评定机构基础档案',
			span: 24,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构名称' }],
		},
		{
			label: '所属区域',
			prop: 'areas_name',
			type: 'text',
			span: 8,
		},
		{
			label: '机构地址',
			prop: 'organizationAddress',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构地址' }],
		},
		{
			label: '机构类别',
			prop: 'organizationType',
			propName: 'organizationTypeLabel',
			type: 'remoteSelect',
			code: 'ORG_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择机构类别' }],
		},
		{
			label: '法定代表人姓名',
			prop: 'deputyUserName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入法定代表人姓名' }],
		},
		{
			label: '法定代表人联系电话',
			prop: 'deputyUserPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入法定代表人联系电话' }],
		},
		{
			label: '机构负责人姓名',
			prop: 'orgLeaderName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构负责人姓名' }],
		},
		{
			label: '机构负责人联系方式',
			prop: 'orgLeaderPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构负责人联系方式' }],
		},
		{
			label: '项目负责人姓名',
			prop: 'projectLeaderName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入项目负责人姓名' }],
		},
		{
			label: '项目负责人联系方式',
			prop: 'projectLeaderPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入项目负责人联系方式' }],
		},
		{
			label: '核定床位数',
			prop: 'realBedNum',
			type: 'text',
			append: '张',
			span: 8,
			rules: [{ required: true, message: '请输入核定床位数' }],
		},
		{
			label: '机构统一社会信用代码',
			prop: 'creditCode',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构统一社会信用代码' }],
		},
		{
			label: '营业执照(民非)证号',
			prop: 'organizationLicenseImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 4,
			multiple: false,
			span: 8,
		},
		{
			label: '机构设置证号(备案)',
			prop: 'organizationFilingImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 4,
			multiple: false,
			span: 8,
		},
		{
			label: '建筑工程消防验收合格意见书',
			prop: 'passAdviceImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 4,
			multiple: false,
			span: 8,
		},
		{
			label: '食品经营许可证',
			prop: 'foodPermitImgs',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 4,
			multiple: false,
			span: 8,
		},
		// 评估档案
		{
			type: 'DividerHtml',
			modelValue: '评估档案',
			span: 24,
		},
		{
			label: '申报日期',
			prop: 'declareDate',
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请选择申报日期' }],
		},
		{
			label: '申报星级等级',
			prop: 'declareLevel',
			propName: 'declareLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
		},
		{
			label: '评定日期',
			prop: 'evaluateDate',
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请选择申报日期' }],
		},
		{
			label: '关键项星级',
			prop: 'criticalLevel',
			propName: 'criticalLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择申报星级等级' }],
		},
		{
			label: '环境评分',
			prop: 'environment',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '设施设备评分',
			prop: 'facilityEquipment',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '运营设备评分',
			prop: 'operateEquipment',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '服务评分',
			prop: 'service',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请进行评分' }],
		},
		{
			label: '现场评定星级',
			prop: 'evaluateLevel',
			propName: 'evaluateLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择现场评定星级' }],
		},
		{
			label: '最终星级',
			prop: 'ultimatelyLevel',
			propName: 'ultimatelyLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择最终星级' }],
		},
		{
			label: '评定人员',
			prop: 'evaluateStaff',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '评定单位',
			prop: 'evaluateUnit',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
		{
			label: '数据来源',
			prop: 'dateSource',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
		},
	],
}

export const baseConfig = {
	pageName: '养老机构等级评定',
	dictcodes: ['ORG_LEVEL', 'ORG_TYPE'],
	rowKey: 'id',
	addLabel: '添加',
	tipLabel: 'organizationName',
	exportMqTopic: '/ning/export/',
	api: {
		moreSearch: 'view_dpOrgLevelEvaluate_search',
		add: 'dpOrgLevelEvaluate_add',
		edit: 'dpOrgLevelEvaluate_edit',
		index: 'dpOrgLevelEvaluate_page',
		delete: 'dpOrgLevelEvaluate_del',
		export: 'dpOrgLevelEvaluate_export',
		import: 'dpOrgLevelEvaluate_import',
	},
	paramsObj: {
		code: 2024,
	},
	auth: {
		// add: 'view_dpOrgLevelEvaluate_add',
		index: 'view_dpOrgLevelEvaluate_page',
		// edit: 'view_dpOrgLevelEvaluate_edit',
		delete: 'view_dpOrgLevelEvaluate_del',
		mulitSet: 'mulitSet',
		// export: 'view_dpOrgLevelEvaluate_export',
		// import: 'view_dpOrgLevelEvaluate_import',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'detail',
			auth: '',
			text: true,
			show: true,
		},
		// {
		// 	icon: 'editor',
		// 	label: '编辑',
		// 	type: 'primary',
		// 	operate: 'edit',
		// 	auth: 'view_dpOrgLevelEvaluate_edit',
		// 	text: true,
		// 	show: true,
		// },
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	dialogConfig: {
		width: '90%',
		// fullscreen: true
	},
	moreSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '评定对象',
				prop: 'organizationName',
				span: 6,
			},
			{
				label: '所属地区',
				propName: 'areas_name',
				type: 'AplidAreaSelect',
				span: 6,
			},
			{
				label: '评定单位',
				prop: 'evaluateUnit',
				type: 'input',
				span: 6,
			},
			{
				label: '评定人员',
				prop: 'evaluateStaff',
				type: 'input',
				span: 6,
			},
			{
				label: '评定时间',
				prop: 'evaluateDate',
				type: 'date',
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
				span: 6,
			},
			{
				label: '评定结果',
				prop: 'ultimatelyLevel',
				type: 'remoteSelect',
				code: 'ORG_LEVEL',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
			{
				label: '数据来源',
				prop: 'dateSource',
				type: 'input',
				span: 6,
			},
		],
	},

	tableConfig,
	detailConfig,
	formConfig,
	beforeOnLoadFormate: async (params) => {
		const areasNameObj = getAreaObj(params.areas_name, 'belong')
		const areasObj = getAreaObj(params.areas, 'belong')
		// 全字段搜索
		params = toSearchHandle(moreSearchConfig, {}, params)
		return Promise.resolve({
			...params,
			...areasNameObj,
			...areasObj,
			areas: undefined,
			areas_name: undefined, // 区域
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areas_name = getAreaObj(item, 'belong')
			return {
				...item,
				areas_name,
				tableAreaName: [item.belongAreaName, item.belongStreetName, item.belongCommunityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
